<?php

namespace common\base;

use yii\web\HttpException;

/**
 * ModelHttpException represents a "Method Not Allowed" HTTP exception with status code 405.
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class InvalidArgumentException extends \yii\base\InvalidArgumentException {

    protected $code = '3333';

    /**
     * @return string the user-friendly name of this exception
     */
    public function setCode() {
        return $this->code = '2222';
    }

    /**
     * Constructor.
     * @param string $message error message
     * @param int $code error code
     * @param \Exception $previous The previous exception used for the exception chaining.
     */
    public function constructsssss($message = null, $error = null, $code = 418, \Exception $previous = null) {
        if (!empty($error)) {
            $append = '';
            if (is_string($error)) {
                $append = $error;
            } elseif (is_array($error)) {
                $append = array_shift($error);
            } else {
                $append = print_r($error, true);
            }
            if ($message) {
                $message .= ': ';
            }
            $message .= $append;
        }
        parent::__construct($code, $message, $code, $previous);
    }

}
